//+--------------------------------------------------------------------------------
//| Copyright (c) 2012 - 2013 ### an.vuongngocduy
//| This file is a part of Compact Game Engine (CGE)
//+--------------------------------------------------------------------------------
#ifndef __CGE_IMAGETRANSCODERTGA_H__
#define __CGE_IMAGETRANSCODERTGA_H__

#include "cgeImageTranscoder.h"

namespace cge
{
	namespace gfx
	{
		//! Support reading and writing image from Targa or TGA file / buffer
		class ImageTranscoderTGA : public ImageTranscoder
		{
		public:
			//! TGA file header
			PACKED_STRUCT_DEF struct FileHeaderTGA
			{
				u8  IdLen;				// size of ID field that follows 18 byte header (0 usually)
				u8  ColorMap;			// type of colour map 0=none, 1=has palette
				u8  ImageType;          // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed

				s16 ColorMapOffset;     // first colour map entry in palette
				s16 ColourMapSize;		// number of colours in palette
				u8  ColourMapBits;      // number of bits per palette entry 15,16,24,32

				s16 XOrigin;            // image x origin
				s16 YOrigin;            // image y origin
				s16 Width;              // image width in pixels
				s16 Height;             // image height in pixels
				u8  BitsPerPixel;       // image bits per pixel 8,16,24,32
				u8  Descriptor;         // image descriptor bits (vh flip bits)
			}
			PACKED_STRUCT_END;


			//! Optional TGA footer
			PACKED_STRUCT_DEF struct FileFooterTGA
			{
				u32 ExtOffset;
				u32 DevAreaOffset;
				c8 Magick[18];
			}
			PACKED_STRUCT_END;


		public:
			//! Load image from stream that contains TGA data
			virtual s8 LoadImage(Stream& inStream, Image& image) const;


			//! Write image to stream using TGA format 
			virtual s8 SaveImage(Stream& outStream, const Image& image) const;
		};
	}
}

#endif//__CGE_IMAGETRANSCODERTGA_H__